#include "Wall.h"

Wall::Wall(double _width, b2Vec2 p1, b2Vec2 p2, bool _isSensor):
PhysicObject(b2_staticBody, p1.x, p2.y),
isSensor(_isSensor)
{
	double a = (p2.y - p1.y);
	double b = (p2.x - p1.x); 
	double length = sqrt(a*a + b*b);
	double rotation = acos(b/length);

	b2PolygonShape shape;
	shape.SetAsBox(length / (2*Config::PHYSIC_SCALE), _width / (2*Config::PHYSIC_SCALE));
	width = length;
	height = _width;

	
	b2FixtureDef fix;
	fix.friction = 0.5;
	fix.restitution = 0.2;
	fix.shape = &shape;
	fix.isSensor = isSensor;

	addFixture(&fix);

	b2Vec2 pos = p1;
	pos.x += b/2;
	pos.y += a/2;
	pos *= 1/Config::PHYSIC_SCALE;
	body->SetTransform(pos, rotation);

}

Wall::~Wall(void)
{
}
